import * as types from './mutation-types'

export default {
    [types.SET_LOGINED](state) {
        /* eslint no-param-reassign: 0 */
        state.logined = true
    },

    [types.REMOVE_LOGINED](state) {
        state.logined = false
        state.user = null
    },

    [types.SET_USER](state, payload) {
        state.user = payload
    },

    [types.ADD_READED_MESSAGE](state, payload) {
        state.readedMessages.push(payload)
    },

    [types.ADD_UNREAD_MESSAGE](state, payload) {
        // console.log('===:  ', payload)
        state.unreadMessages.push(payload)
    },

    [types.REMOVE_UNREAD_MESSAGE](state, payload) {
        // payload => message.id
        const {unreadMessages} = state
        const index = unreadMessages.findIndex(el => el.id === payload)
        unreadMessages.splice(index, 1)
    },

    [types.SET_PUBLIC_INFORMATION](state, payload) {
        state.public_Information = payload;
    },

    [types.SET_USER_AUTHS](state, auths) {
        const _auths = []
        for (let i = 0; i < auths.length; i++) {
            for (const key in auths[i]) {
                // console.log(i, state.user.auths[i][key])
                for (let j = 0; j < auths[i][key].length; j++) {
                    _auths.push(auths[i][key][j].auth)
                }
            }
        }
        state.auths = _auths
    },

    [types.SET_REFERSH_OPTION](state, option) {
        state.refreshOptions = option
    },
}
